//
//  HttpRequest.h
//  NewDemo
//
//  Created by Andy_chen on 11/16/15.
//  Copyright © 2015 Andycchen. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AFNetworking/AFNetworking.h>

@interface HttpRequest : NSObject
{
    BOOL _isCancelled;
}
@property (nonatomic, strong)NSString *requestKey;
@property (nonatomic, strong)NSString *requestUrl;
@property (copy) void (^success)(AFHTTPRequestOperation *operation, id responseObject);
@property (copy) void (^failure)(NSError* error);

/**
 *  HTML “GET”请求
 *
 *  @param URLString  请求URL
 *  @param parameters 参数
 *  @param success    请求成功block
 *  @param failure    请求失败block
 */
- (void)getHTMLDataWithUrl:(NSString *)URLString
                parameters:(NSDictionary *)parameters
                   success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))success
                   failure:(void(^)(NSError * error))failure;

/**
 *  HTML “POST”请求
 *
 *  @param URLString  请求URL
 *  @param parameters 参数
 *  @param success    请求成功block
 *  @param failure    请求失败block
 */
- (void)postHTMLDataWithUrl:(NSString *)requestUrl
                 parameters:(NSDictionary *)parameters
                    success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))success
                    failure:(void(^)(NSError * error))failure;

/**
 *  JSON “GET”请求
 *
 *  @param URLString  请求URL
 *  @param parameters 参数
 *  @param success    请求成功block
 *  @param failure    请求失败block
 */
- (void)getJSONDataWithUrl:(NSString *)URLString
                parameters:(NSDictionary *)parameters
                   success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))success
                   failure:(void(^)(NSError * error))failure;

/**
 *  JSON “POST”请求
 *
 *  @param URLString  请求URL
 *  @param parameters 参数
 *  @param success    请求成功block
 *  @param failure    请求失败block
 */
- (void)postJSONDataWithUrl:(NSString *)requestUrl
                 parameters:(NSDictionary *)parameters
                    success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))success
                    failure:(void(^)(NSError * error))failure;

/**
 *  XML “GET”请求
 *
 *  @param URLString  请求URL
 *  @param parameters 参数
 *  @param success    请求成功block
 *  @param failure    请求失败block
 */
- (void)getXMLDataWithUrl:(NSString *)URLString
               parameters:(NSDictionary *)parameters
                  success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))success
                  failure:(void(^)(NSError * error))failure;

/**
 *  XML “POST”请求
 *
 *  @param URLString  请求URL
 *  @param parameters 参数
 *  @param success    请求成功block
 *  @param failure    请求失败block
 */
- (void)postXMLDataWithUrl:(NSString *)requestUrl
                parameters:(NSDictionary *)parameters
                   success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))success
                   failure:(void(^)(NSError * error))failure;

/**
 *  Image
 *
 *  @param URLString  请求URL
 *  @param parameters 参数
 *  @param success    请求成功block
 *  @param failure    请求失败block
 */
- (void)getImageDataWithUrl:(NSString *)URLString
                 parameters:(NSDictionary *)parameters
                    success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))success
                    failure:(void(^)(NSError * error))failure;

- (void)postImageDataWithUrl:(NSString *)URLString
                  parameters:(NSDictionary *)parameters
                     success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))success
                     failure:(void(^)(NSError * error))failure;

/**
 *   将数据以表单的形式上传到服务器 Content-Type
 *
 *  @param URLString  请求URL
 *  @param data       表单数据NSData
 *  @param success    请求成功block
 *  @param failure    请求失败block
 */
- (void)postMultiFormDataWithUrl:(NSString*)URLString
                        FormData:(NSData*)data
                         success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))success
                         failure:(void(^)(NSError * error))failure;

/**
 * 显示取消网络请求
 *
 *  @return BOOL 判定是否取消该请求
 */
-(BOOL)isCancelled;

/**
 *  取消网络请求
 */
-(void)requestCancel;

/**
 *  显示网络请求消耗的时间
 */
-(void )printfUseUpSystemTime:(BOOL)setOrget;


/**
 *  取消AFNetworking的网络请求
 */
-(void)cancelAFURLRequest;

@end

